package TUILayer;//makes this class a part of the TUILayer package
import java.util.Scanner;
import java.util.ArrayList;
import ControlLayer.*;//The TUILayer needs to know the ControlLayer

/**
 * 
 * 
 * @author (Brian, Jesper, Jesper, Hoang) 
 * @version ()
 */
public class OrderUI
{   
    //Instance variabler
    private OrderCtr orderCtr;
    
    //Constructor
    public OrderUI()
    {
        orderCtr = new OrderCtr();      
    }
    
    //Metode til at starte menuen
    public void start()
    {   
        orderMenu();
    }
    
    //Metode til at håndtere order menuen
    public void orderMenu()
    {
       boolean exit = false;
       while(!exit)
       {
          int choise = skrivOrderMenu(); 
          if(choise == 1)
          {   
              
          }
          else
          {
              if(choise == 2)
              {
                    
                    opretOrder();
              }  
              else
              {
                  if(choise == 3)
                  {
                      
                      
                  }  
                  else
                  {
                      if(choise == 4)
                      {
                          
                          
                      }
                      else
                      {
                            if(choise == 5)
                            {
                                exit = true;
                            }
                            else
                            {
                                System.out.println("Forkert input. Prøv igen!");
                                pause();
                            }
                        }//end else
                    }//end else
                }//end else
            }//end else
            
       }//end while
    }
    
    //Metode til at skrive order menuen 
    public int skrivOrderMenu()
    {      
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Order Menu ***");
            System.out.println(" (1) Find Order");
            System.out.println(" (2) Opret Order");
            System.out.println(" (3) Slet Order");
            System.out.println(" (4) Opdater Orderstatus");
            System.out.println(" (5) Tilbage");
            System.out.print("\n Indtast valg: ");
            
            int choise = keyboard.nextInt();
            return choise;
        }
    
    //Metode til at læse id input
    public int inputId()
    {   
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Skriv Id:  ");
           try{
             id = keyboard.nextInt();
             ok = true;
           }
           catch (Exception e)
            {
             System.out.println("Der skal indtastes et tal -  prøv igen");
             int input = keyboard.nextInt();
           }
        }//end while
        return id;
    }
    
    //Metode til at læse kundeid input
    public int inputKundeId()
    {   
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Skriv Kunde ID:  ");
           try{
             id = keyboard.nextInt();
             ok = true;
           }
           catch (Exception e)
            {
             System.out.println("Der skal indtastes et tal -  prøv igen");
             int input = keyboard.nextInt();
           }
        }//end while
        return id;
    }
    
    //Metode til at læse vareid input
    public int inputVareId()
    {   
        boolean ok = false;
        int id = 0;
        while(!ok)
        {
           Scanner keyboard = new Scanner(System.in);
           System.out.println(" Skriv Vare ID:  ");
           try{
             id = keyboard.nextInt();
             ok = true;
           }
           catch (Exception e)
            {
             System.out.println("Der skal indtastes et tal -  prøv igen");
             int input = keyboard.nextInt();
           }
        }//end while
        return id;
    }
    
    //Metode til at læse vare antal input
    public int inputAntal()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.println(" Indtast Antal Vare:  ");
         int vareAntal = keyboard.nextInt();
         return vareAntal;
    }
    
    //Metode til at læse status input
    public String inputStatus()
    {
         Scanner keyboard = new Scanner(System.in);  
         System.out.println(" Indtast Orderstatus:  ");
         String orderStatus = keyboard.nextLine();
         return orderStatus;
    }
    
    //metode til at oprette en order
    private void opretOrder()
    {
        System.out.println();
        System.out.println(" Opret ny Order:");
        
        
        int _id = inputId();
        int _kundeId = inputKundeId();
        int _vareId = inputVareId();
        int _antal = inputAntal();
        String _status = inputStatus();
        
        orderCtr.createOrder(_id, _kundeId, _vareId, _antal, _status);
        
        System.out.println();
        System.out.println(" Ordren er blevet oprettet!");
        
        pause();
    }
    
    //Metode til at pause order menuen
    private void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }
}            
        
